<template>
    <div>
        <p>&nbsp;
            <button @click="list(1)" class="btn btn-white btn-default btn-round">
                <i class="ace-icon fa   fa-arrow-circle-o-down red2"></i>
                刷新
            </button>
        </p>
        <table id="simple-table" class="table  table-bordered table-hover">
            <thead>
            <tr>
                                        <th>手机号</th>
                        <th>密码</th>
                        <th>昵称</th>
                        <th>头像url</th>
                        <th>注册时间</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody>
            <tr v-for="member in members">
                            <td>{{member.mobile}}</td>
                            <td>{{member.password}}</td>
                            <td>{{member.name}}</td>
                            <td>{{member.photo}}</td>
                            <td>{{member.registerTime}}</td>
                <td>
                    <div class="hidden-sm hidden-xs btn-group">
                        <button @click="update(member)" class="btn btn-xs btn-info">
                            <i class="ace-icon fa fa-pencil bigger-120"></i>
                        </button>

                        <button @click="del(member.id)" class="btn btn-xs btn-danger">
                            <i class="ace-icon fa fa-trash-o bigger-120"></i>
                        </button>
                    </div>

                    <div class="hidden-md hidden-lg">
                        <div class="inline pos-rel">
                            <button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown" data-position="auto">
                                <i class="ace-icon fa fa-cog icon-only bigger-110"></i>
                            </button>

                            <ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
                                <li>
                                    <a href="#" class="tooltip-info" data-rel="tooltip" title="View">
																			<span class="blue">
																				<i class="ace-icon fa fa-search-plus bigger-120"></i>
																			</span>
                                    </a>
                                </li>

                                <li>
                                    <a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
																			<span class="green">
																				<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
																			</span>
                                    </a>
                                </li>

                                <li>
                                    <a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
																			<span class="red">
																				<i class="ace-icon fa fa-trash-o bigger-120"></i>
																			</span>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
        <pagination ref="pagination" v-bind:list="list"  v-bind:itemCount="2" style="float: right" ></pagination>
        <div id="form-modal" class="modal fade" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">会员表单</h4>
                    </div>
                    <div class="modal-body">
                        <form class="form-horizontal">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">手机号</label>
                                            <div class="col-sm-10">
                                                <input v-model="member.mobile" class="form-control">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">密码</label>
                                            <div class="col-sm-10">
                                                <input v-model="member.password" class="form-control">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">昵称</label>
                                            <div class="col-sm-10">
                                                <input v-model="member.name" class="form-control">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">头像url</label>
                                            <div class="col-sm-10">
                                                <input v-model="member.photo" class="form-control">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">注册时间</label>
                                            <div class="col-sm-10">
                                                <input v-model="member.registerTime" class="form-control">
                                            </div>
                                        </div>
                        </form>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button v-on:click="save()" type="button" class="btn btn-primary">保存</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
        </div>
    </div>
</template>
<script>
    import pagination from "../../components/pagination";
    export default {
        name: 'member',
        components:{pagination},
        mounted() {//在组件内容被渲染到页面之【后】立即执行的函数
            let _this = this;
            $('body').attr('class', 'no-skin');
            //默认分页每页显示5条
            _this.$refs.pagination.size = 5;
            _this.list(1);
        },
        data(){
            return{
                members:[],
                member:{}
            }
        },
        methods:{
            //进行Axios异步通讯
            list(page){
                //加载框显示
                Loading.show();
                let _this = this;
                _this.$ajax.post(process.env.VUE_APP_SERVER +"/business/member/getAllMembers",{
                    page:page,
                    size:_this.$refs.pagination.size,
                }).then(function (response) {
                    let responseBody = response.data;//获取到axios响应的结果对象
                    _this.members = responseBody.list;//获取查询的结果
                    //渲染分页组件的效果
                    _this.$refs.pagination.render(page, responseBody.total);
                    //加载框显示
                    Loading.hide();
                });
            },
            //添加操作
            add(){
                //清空当前对象
                let _this = this;
                _this.member = {};
                //弹出添加窗口
                $("#form-modal").modal("show");
            },
            //更新操作
            update(member){
                let _this = this;
                //获取选中行的数据
                _this.member = $.extend({}, member);
                //弹出添加窗口
                $("#form-modal").modal("show");
            },
            //调用后台接口完成数据的添加和更新
            save(){
                let _this = this;
                _this.$ajax.post(process.env.VUE_APP_SERVER +"/business/member/save",_this.member).then(function (response) {
                    let responseBody = response.data;//获取到axios响应的结果对象
                    //将弹出框消失
                    $("#form-modal").modal("hide");
                    //弹出接口返回的提示
                    Toast.success(responseBody.msg);//获取查询的结果
                    //刷新页面
                    _this.list(1);
                    /* //渲染分页组件的效果
                     _this.$refs.pagination.render(page, responseBody.total);*/
                });
            },
            //删除数据
            del(id){
                let _this = this;
                //确认框
                Confirm.show("数据删除后将无法恢复,确定删除吗?",function(){
                    _this.$ajax.get(process.env.VUE_APP_SERVER +"/business/member/deleteMember?id="+id).then(function (response) {
                        let responseBody = response.data;//获取到axios响应的结果对象
                        //弹出接口返回的提示
                        Toast.success(responseBody.msg);//获取查询的结果
                        //刷新页面
                        _this.list(1);
                        /* //渲染分页组件的效果
                         _this.$refs.pagination.render(page, responseBody.total);*/
                    });
                });

            }
        }
    }
</script>
